package com.yanqu.road.server.logic.activity.condition.rank.union;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseUnionRankActivityCondition;
import com.yanqu.road.server.manger.rank.YRankMgr;
import com.yanqu.road.server.manger.union.UnionActivityMgr;

/**
 * 商会经验提升冲榜 冲榜活动
 */
public class UnionExpRiseRankCondition extends BaseUnionRankActivityCondition {

	public UnionExpRiseRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.UnionExpRiseRank.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.UnionExpRiseRank.getValue(), handle);
	}

    @Override
    public void initDefaultValue() {
//		setUnionRankActivityDefaultValue(player.getUserInfo().getUnionUid(), UnionRiseRankArgs.NOTIFY_TYPE_NORMAL);
    }

    @Override
	protected void player_BoardLevelHandle(Object object) {
		UnionRiseRankArgs args = (UnionRiseRankArgs) object;
		if(null != args) {

			// 跨服的改成商会活动分组了
			if (activityInfo.getType() == eActivityType.CrossUnionActivity.getValue()) {
				setValue(getValue().add(args.getValue()));
				YRankMgr.uploadUnionYRank(baseActivityData.getUserActivityConditionData(getConditionId()), args.getUnionUid(), args.getType());
				return;
			}

			setUnionRankActivityValue(getValue().add(args.getValue()), args.getUnionUid(), args.getType());
			if(UnionRiseRankArgs.NOTIFY_TYPE_DELETE == args.getType()){//解散商会
				UnionActivityMgr.removeUnionActivityRank(activityInfo.getActivityId(), args.getUnionUid());
			}
		}
	}
}
